package com.example.service.impl;

import com.example.mapper.equipmentManagementMapp;
import com.example.pojo.equTestListPojo;
import com.example.pojo.equipmentManagementPojo;
import com.example.pojo.equipmentTechnologyPojo;
import com.example.service.equipmentManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:equipmentManagementImpl
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/9/22 23:05
 * @Version 1.0
 */
@Service
@Slf4j
public class equipmentManagementImpl implements equipmentManagementService {
    @Autowired
    private equipmentManagementMapp equipmentManagementMapp;
    //插入一行《工装台账》
    public void insertOne(equipmentManagementPojo equipmentManagementPojo){
        //组合修改时间、创建时间
        equipmentManagementPojo.setUpdateTime(LocalDateTime.now());
        equipmentManagementPojo.setEstablishTime(LocalDateTime.now());
        equipmentManagementMapp.insertOne(equipmentManagementPojo);
    }
    //对工装台账的目录进行筛选
    public List<equipmentManagementPojo> queryDifferentByOne(Map<String, Object> parameters){
        int type=(int) parameters.get("type");
        String fistField=(String) parameters.get("fistField");
        String secondField=(String) parameters.get("secondField");
        List<equipmentManagementPojo> equipmentManagementPojoList=null;

        if (type==1){
            //查询装配车间工装台账
            equipmentManagementPojoList=equipmentManagementMapp.queryDifferentByType1();
        }
        else if (type==2){
            equipmentManagementPojoList=equipmentManagementMapp.queryDifferentByType2();
        }
        else if (type==3){
            equipmentManagementPojoList=equipmentManagementMapp.queryDifferentByType3();
        }
        return equipmentManagementPojoList;
    }
    //根据传来的车间名称、存放位置，查询数据(工装台账)
    public List<equipmentManagementPojo> SelectClampData(Map<String, Object> map){
        String filedVal1=(String) map.get("filedVal1");
        String filedVal2=(String) map.get("filedVal2");
        List<equipmentManagementPojo> equipmentManagementPojoList=null;
        int type=(int) map.get("type");
        if (type==1 || type==2){
            equipmentManagementPojoList=equipmentManagementMapp.SelectClampData(filedVal1,filedVal2);
        }
        else if (type==3){
            equipmentManagementPojoList=equipmentManagementMapp.SelectClampDataType3(filedVal2);
        }
        return equipmentManagementPojoList;
    }
    //根据id，修改一行信息
    public void editOne(equipmentManagementPojo equipmentManagementPojo){
        //组合修改时间
        equipmentManagementPojo.setUpdateTime(LocalDateTime.now());
        equipmentManagementMapp.editOne(equipmentManagementPojo);
    }
    //插入一行数据（工装技术条件）
    public void technologyInsertOne(equipmentTechnologyPojo equipmentTechnologyPojo){
        //组合创建时间、修改时间
        equipmentTechnologyPojo.setUpdateTime(LocalDateTime.now());
        equipmentTechnologyPojo.setEstablishTime(LocalDateTime.now());
        equipmentManagementMapp.technologyInsertOne(equipmentTechnologyPojo);
    }
    //查询树形导航结构,查询的是存放部位不重复，并且按照要求排序的,接收的是两个字段的字段名称。形成一个树形导航的数组（工装技术条件）
    public List<equipmentTechnologyPojo> queryTechnologyDifferentByOne(Map<String, Object> parameters){
        int type=(int) parameters.get("type");
        String fistField=(String) parameters.get("fistField");
        String secondField=(String) parameters.get("secondField");
        List<equipmentTechnologyPojo> equipmentTechnologyPojoList=null;

        if (type==1){
            //查询装配车间工装台账
            equipmentTechnologyPojoList=equipmentManagementMapp.queryTechnologyDifferentByType1();
        }
        else if (type==2){
            equipmentTechnologyPojoList=equipmentManagementMapp.queryTechnologyDifferentByType2();
        }
        else if (type==3){
            equipmentTechnologyPojoList=equipmentManagementMapp.queryTechnologyDifferentByType3();
        }
        return equipmentTechnologyPojoList;
    }
    //根据传来的车间名称，存放位置，查询数据（工装技术条件）
    public List<equipmentTechnologyPojo> SelectTechnologyData(Map<String, Object> map){
        String filedVal1=(String) map.get("filedVal1");
        String filedVal2=(String) map.get("filedVal2");
        List<equipmentTechnologyPojo> equipmentTechnologyList=null;
        int type=(int) map.get("type");
        if (type==1 || type==2){
            equipmentTechnologyList=equipmentManagementMapp.SelectTechnologyData(filedVal1,filedVal2);
        }
        else if (type==3){
            equipmentTechnologyList=equipmentManagementMapp.SelectTechnologyDataType3(filedVal2);
        }
        return equipmentTechnologyList;
    }
    //根据Id修改数据（工装技术条件）
    public void editTechnologyOne(equipmentTechnologyPojo equipmentTechnologyPojo){
        //组合修改时间
        equipmentTechnologyPojo.setUpdateTime(LocalDateTime.now());
        equipmentManagementMapp.editTechnologyOne(equipmentTechnologyPojo);
    }
    //向工装检测数据中插入一行检测数据
    public void equTestInsertOne(equTestListPojo equTestListPojo){
        //组合时间
        equTestListPojo.setEstablishTime(LocalDateTime.now());
        equTestListPojo.setUpdateTime(LocalDateTime.now());
        equipmentManagementMapp.equTestInsertOne(equTestListPojo);
    }
    //    查询最后检测的一条数据
    public equTestListPojo equLastTimeTest(equTestListPojo equTestListPojo){
        equTestListPojo equTestList=equipmentManagementMapp.equLastTimeTest(equTestListPojo);
        return equTestList;
    }
}
